package _1到100;

/**
 * @Author: WangYongGan
 * @Date: 2021/11/20 23:49
 * @Description:
 */
public class _5最长字符串 {
    public static String longestPalindrome(String s) {
        if (new StringBuffer(s).reverse().toString().equals(s))
            return s;
        int i = 0, n = s.length();
        for (; i < n / 2; i++) {
            if (s.charAt(i) != s.charAt(n - i - 1))
                break;
        }
        if (i == s.length())
            return s;
        String s1 = longestPalindrome(s.substring(1));
        String s2 = longestPalindrome(s.substring(0, s.length() - 1));
        return s1.length() > s2.length() ? s1 : s2;
    }

    public static void main(String[] args) {
        System.out.println(longestPalindrome("babaddtattarrattatddetartrateedredividerb"));
    }
}
